package com.pz.cloud.framework.workflow.listener;

import com.pz.cloud.framework.business.workflow.entity.WaitDone;
import com.pz.cloud.framework.business.workflow.enums.WorkflowEnum;
import com.pz.cloud.framework.util.BizUtil;
import com.pz.cloud.framework.business.workflow.service.IWaitDoneService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.delegate.event.ActivitiEntityEvent;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.jeecg.common.util.SpringContextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * 3hmzz 任务完成的事件监听器
 */
public class TaskCompleteListener implements ActivitiEventListener {
    private final static Logger LOG = LoggerFactory.getLogger(ActivitiEventListener.class);
    /**
     * Called when an event has been fired
     *
     * @param event the event
     */
    @Override
    public void onEvent(ActivitiEvent event) {
        IWaitDoneService waitDoneService = SpringContextUtils.getBean(IWaitDoneService.class);

        ActivitiEntityEvent entityEvent = (ActivitiEntityEvent) event;
        TaskEntity task = (TaskEntity) entityEvent.getEntity();

//        WaitDone waitDone = waitDoneService.getById(task.getId());
//        if(waitDone!=null){
//            waitDone.setDealTime(new Date());
//            waitDone.setStatus(WorkflowEnum.WaitDoneStatus.已完成.getStatus());
//            waitDone.setDealUserId(BizUtil.getUserId());
//            waitDone.setDealUserName(BizUtil.getUser().getRealname());
//            waitDone.setOpinion((String) task.getVariable("opinion"));
//            waitDone.setResult((String) task.getVariable("result"));
//            waitDoneService.updateById(waitDone);
//        }
    }

    /**
     * @return whether or not the current operation should fail when this listeners execution throws an exception.
     */
    @Override
    public boolean isFailOnException() {
        return false;
    }
}
